package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.ChestAddReq;
import com.yimils.core.goods.dto.ChestUpdateReq;
import com.yimils.core.goods.serivce.ChestService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class ChestController {
    @Resource(name = "chestService")
    ChestService chestService;

    @PostMapping("/chest/save")
    public RspBase saveChest(@RequestBody ChestAddReq chestAddReq) {
        if (chestService.saveChest(chestAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/chest/update")
    public RspBase updateChest(@RequestBody ChestUpdateReq chestUpdateReq) {
        if (chestService.updateChest(chestUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/chest/delete")
    public RspBase deleteChest(List<Long> chestIds) {
        if (chestService.deleteChest(chestIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/chest/list")
    public RspBase listChest() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", chestService.listChest());
        return rsp;
    }

}
